import request from '@/utils/request';

export type CircleBasicInfo = {
	id : number;
	circleCode : string;
	circleName : string;
	circleDescription : string;
	circleAvatar : string;
	ownerUser : string;
	systemName : string;
	memberCount : string;
	postCount : string;
	heatScore : number;
	approvalStatus : string;
	createdBy : string;
	createdTime : string;
	updatedBy : string;
	updatedTime : string;
	deletedFlag : string;
	createUserId : number
};

// 查询帖子管理列表
export const getHotCircle = () => {
	return request({
		url: '/circle/circle/hot',
		method: 'GET'
	});
}

// 获取所有圈子
export const getCircleList = () => {
	return request({
		url: '/circle/circle/all',
		method: 'GET'
	});
}

// 查询圈子
export const queryCircleByCircleName = (circleName : string) => {
	return request({
		url: `/circle/circle/query/${circleName}`,
		method: 'GET'
	});
}

// 根据标签id获取圈子
export const getCircleByTagId = (tagId : number) => {
	return request({
		url: `/circle/circle/tag/${tagId}`,
		method: 'GET'
	});
}


// 获取我加入的圈子
export const getJoinedCircle = (userId : number) => {
	return request({
		url: `/circle/circle/joined/${userId}`,
		method: 'GET'
	});
}

// 获取我创建的圈子
export const getCircleCreatedByMe = (userId : number) => {
	return request({
		url: `/circle/circle/created/${userId}`,
		method: 'GET'
	});
}

// 获取我正在被审核的圈子
export const getMyApprovalCircle = (userId : number) => {
	return request({
		url: `/circle/circle/approval/${userId}`,
		method: 'GET'
	});
}

// 用户申请创建新圈子
export const applyCreateCircle = (data : CircleBasicInfo) => {
	return request({
		url: '/circle/circle/apply',
		method: 'POST',
		data
	});
}

// 获取所有等级规则系统名称
export const getLevelSystemNames = () => {
	return request({
		url: `/circle/circle/levelSystemNames`,
		method: 'GET'
	});
}

export type CircleTagsRel = {
	circleId : number;
	tagId : number;
}

// 新增圈子与标签中间表
export const insertCircleTagsRel = (data : CircleTagsRel) => {
	return request({
		url: '/circle/circle/ctr',
		method: 'POST',
		data
	});
}

// 批量新增圈子与标签中间表
export const insertBatchCircleTagsRel = (data : CircleTagsRel[]) => {
	return request({
		url: '/circle/circle/ctrs',
		method: 'POST',
		data
	});
}

// 获取圈子基础信息详细信息
export const getCircleDetail = (id : number) => {
	return request({
		url: `/circle/circle/${id}`,
		method: 'GET'
	});
}

/**
 * 圈子的成员关系实体
 */
export type CircleMemberRelation = {
	/** 自增ID */
	id : number;
	/** 圈子ID */
	circleId : number;
	/** 用户ID */
	userId : number;
	/** 成员角色 ,1-会员 2-管理员 3-圈主*/
	memberRole : 1 | 2 | 3;
	/** 加入时间 */
	joinedTime : string;
	/** 成员状态 ,1-正常 2-已退出*/
	memberStatus : 1 | 2;
	/** 黑名单状态 ,0-正常 1-黑名单*/
	blacklistStatus : 0 | 1;
	/** 用户昵称 */
	nickName : string;
	/** 用户头像 */
	avatar : string;
	/** 用户等级 */
	userLevel : string;
}

// 查询圈子成员列表（包含用户信息）
export const getMemberList = (circleId : number) => {
	return request({
		url: `/circle/member/memberList/${circleId}`,
		method: 'GET'
	});
}

// 获取当前用户在圈子中的角色
export const getCurrentUserRole = (circleId : number) => {
	return request({
		url: `/circle/member/currentUserRole/${circleId}`,
		method: 'GET'
	});
}

// 将用户加入黑名单或将用户从黑名单移除
export const setBlacklistMember = (circleId : number, userId : number, status : number) => {
	return request({
		url: `/circle/member/blacklist/${circleId}/${userId}/${status}`,
		method: 'PUT'
	})
}

// 移除圈子成员
export const removeMember = (circleId : number, userId : number) => {
	return request({
		url: `/circle/member/remove/${circleId}/${userId}`,
		method: 'DELETE'
	})
}

// 转让圈主
export const updateTransferOwner = (circleId : number, userId : number, newOwnerName : string) => {
	return request({
		url: `/circle/member/owner/${circleId}/${userId}/${newOwnerName}`,
		method: 'PUT'
	})
}

// 用户加入圈子
export const joinCircle = (circleId : number) => {
	return request({
		url: `/circle/member/join/${circleId}`,
		method: 'POST'
	})
}

// 用户退出圈子
export const leaveCircle = (circleId : number) => {
	return request({
		url: `/circle/member/leave/${circleId}`,
		method: 'POST'
	})
}